<?php
header("content-type:text/html;charset=utf8");
include('conn.php');
if($conn){
    switch ($_GET['action']){
        case 'add':
            echo "<script>alert('add!!!!');</script>";
            $name = $_POST['name'];
            $sex = $_POST['sex'];
            $age = $_POST['age'];
            $class = $_POST['class'];
            $sql = "insert into stu (‘name’, sex, age, class) values ('$name', '$sex','$age','$class')";
            echo "12332123132";
            $rw = mysqli_query($conn,$sql);
            if ($rw > 0){
                echo "<script>alert('添加成功');</script>";
            }else{
                echo "<script>alert('添加失败');</script>";
            }
            header('Location: main.php');
            break;
        case 'del':
            $id = $_GET['id'];
             $sql = "update xiaoxi set flag=1 where id='$id'";
            $rw = mysqli_query($conn,$sql);
            if ($rw > 0){
                echo "<script>alert('删除成功');</script>";
            }else{
                echo "<script>alert('删除失败');</script>";
            }
            header('Location: main.php');
            break;
        case 'edit'://post
           $id = $_GET['id'];
//    echo $id, $age, $age, $name;
            $sql = "update xiaoxi set flag=1 where id='$id';";
//    $sql = "update myapp.stu set name='jike',sex='女', age=24,classid=44 where id=17";
//            print $sql;
            $rw = mysqli_query($conn,$sql);
//            var_dump($rw);
//            die();
            if ($rw > 0){
                echo "<script>alert('更新成功');</script>";
            }else{
                echo "<script>alert('更新失败');</script>";
            }
            header('Location: main.php');
            break;
        default:
            header('Location: amin.php');
            break;
    }
}else{
    die('数据库连接失败' .mysqli_connect_error());
}
?>
